<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Pragma", "no-cache");
	response.setDateHeader("Expires", 0);
	String passstatus=(String)request.getSession().getAttribute("passstatus");
	String unlock=(String)request.getSession().getAttribute("unlock");
%>
<html>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<title>数据库审计系统</title>
<%@ include file="jsp/ext-common.jsp"%>
<style>
<!--
html {
	filter: progid:     DXImageTransform . Microsoft .
		BasicImage(grayscale =     1);
}

.efs-box td {
	padding: 5;
	font: normal normal normal 9pt Arial;
}

.title {
	font: 18pt 黑体;
	color: #ffffff;
}

td {
	font-size: 9pt;
}

-->
</style>
<link rel="stylesheet" type="text/css" href="../../resources/thirdplug/extjs/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="/javascript/sys/ext/ux/css/GroupTab.css">
<link rel="stylesheet" type="text/css" href="../../resources/thirdplug/extjs/src/ux/css/GroupTabPanel.css">
<link rel="stylesheet" type="text/css" href="../../resources/css/icon.css">
<script>
Ext.BLANK_IMAGE_URL = 'javascript/sys/ext/resources/images/default/s.gif';
</script>
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="/dwr/interface/service.js"></script>
<script type="text/javascript" src="/dwr/interface/identifyAction.js"></script>
<script type="text/javascript" src="javascript/util/commonMethod.js"></script>
<script type="text/javascript" src="index.js"></script>
<script type="text/javascript" src="module.js"></script>
<script type="text/javascript" src="javascript/sys/ext/ux/GroupTab.js"></script>
<script type="text/javascript" src="javascript/sys/ext/ux/GroupTabPanel.js"></script>

<!--  此脚本段用于登陆用户角色判断并跳转至相应角色系统     -->
<%                                      
HttpSession sessionObj = request.getSession();

String companyName=(String)request.getSession().getAttribute("aasName");
String firstPageId = "";
String timeOuts = (String)sessionObj.getAttribute("LoginTimeout");

String lastLoginTime = (String)sessionObj.getAttribute("lastLoginTime");
String NowLoginTime = (String)sessionObj.getAttribute("NowLoginTime");
Integer lastToNowHigh = (Integer)sessionObj.getAttribute("lastToNowHigh");
Integer lastToNowMiddle = (Integer)sessionObj.getAttribute("lastToNowMiddle");
Integer lastToNowLow = (Integer)sessionObj.getAttribute("lastToNowLow");


String roleStr = "";
if("审计员".equals("审计员")){
	firstPageId = "ruleFirstPageId";
	roleStr ="审计管理平台";
}
%>
<script type="text/javascript">
window.Ajax_requ = null;//Ajax_requ = null;
</script>


<script type="text/javascript">

	function changePassword() {
		Ext.QuickTips.init();
		Ext.form.Field.prototype.msgTarget='side';
			
		var storelength = new Ext.data.JsonStore({
			url : "pswLenRange.action",
			root : 'temp',
			fields : [{
						name : 'min_pwd_len'
					}, {
						name : 'max_pwd_len'
			}]
		})
		
		storelength.on("load", function() {
			var size = storelength.getTotalCount();
			if(size>0){
				parent.Ext.getCmp('pass').minLength=storelength.getAt(0).get('min_pwd_len');
				parent.Ext.getCmp('pass').maxLength=storelength.getAt(0).get('max_pwd_len');
			}
		
		})
	  storelength.load();
			
		var win = new parent.Ext.Window({
			modal : true,
			title : '修改密码',
			autoHeight : true,
			width : 300,
			closeAction : 'close',
			buttonAlign : 'center',
			items : [{
				xtype : 'form',
				id : 'changePasswordForm',
				frame:true,
	       		labelWidth:80,
				items : [{
					xtype : 'textfield',
					fieldLabel : '旧密码',
					id : 'oldpasswordId',
					name : 'oldpassword',
					inputType : 'password',
					allowBlank:false,
					blankText:'旧密码不能为空'
				},{
					xtype : 'textfield',
					fieldLabel : '新密码',
					name : 'password',
					id : 'pass',
					inputType : 'password',
					regex: /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9]).{8,50}$/,
	                regexText:'密码至8到50个字符组成，必须包含大小写字母、数字、特殊符号',
					blankText:'密码不能为空',
					allowBlank:false
				},{
					xtype : 'textfield',
					fieldLabel : '确认新密码',
					name : 'repassword',
					id : 'repass',
					inputType : 'password',
					allowBlank:false
				}]
			}],
			buttons:[{
				text:'保存',
				handler:function(){
					var oldPass = parent.Ext.getCmp('oldpasswordId').getValue();
					var newPass = parent.Ext.getCmp('pass').getValue();
					var rePass =  parent.Ext.getCmp('repass').getValue();
					
					if(newPass != rePass){
						parent.Ext.Msg.alert('提示','两次密码不一致，请重新输入。');
						return;
					}
					if(!parent.Ext.getCmp('changePasswordForm').getForm().isValid()){
						return;
					}
					
					Ext.Ajax.request({
						url:'updatePassword.action',
						method:'post',
						params: {
							'oldpassword' : oldPass,
							'password' 	  : newPass
						},
						success : function(response, options){
							var arrays = Ext.util.JSON.decode(response.responseText);
							if(arrays.flag=="3"){
								parent.Ext.Msg.alert('提示','原密码不正确，请重新操作。');
							}else if(arrays.flag=="2"){
								parent.Ext.Msg.alert('提示','修改失败，session中的用户信息丢失。');
							}else{
								parent.Ext.Msg.alert('提示','修改密码成功。', function(bt){
									if(bt=='ok'){
										win.close();
									}
								});
							}
						},
						failure:function(response, options){
							parent.Ext.Msg.alert('提示','修改失败。');						
						}
					})
				}
			},{
				text:'重置',
				handler:function(){
					parent.Ext.getCmp('changePasswordForm').getForm().reset();
				}
			}]
		});
	
		win.show(Ext.getBody());
	}
	
	function systemDiagnose(){//系统诊断情况
		  var win = new parent.Ext.Window( {
				title : '系统诊断情况',
				layout : 'fit',
				width : 565,
				height: 420,
				modal : true,
				closeAction : 'close',
				maximizable : false,
				buttonAlign : 'center',
				autoScroll:true,
				html : content(),
				buttons : [{
					text : '关闭',
					handler : function() {
						win.close();
					}
				}]
			}).show();
		}
	
	function sysAboutInfo(){
		var win = new parent.Ext.Window({
			modal : true,
			title : '联系我们',
			autoHeight : true,
			width : 700,
			iconCls : 'main_page_about_menu',
			closeAction : 'close',
			buttonAlign : 'center',
			padding : '10 10 10 10',
			items : [{
				xtype : 'form',
				frame:true,
	       		defaults: {
				    labelWidth:80,
				    width : 490,
				    readOnly : true
				},
	       		items:[{
	       			xtype : 'label',
	       			cls : 'about_info_css',
					html : '欢迎通过以下方式给我们提问题及建议：'
	       		},{
	       			xtype : 'textfield',
					fieldLabel : '公司地址',
					value : '深圳市南山区智恒战略性新兴产业园4栋4楼'
	       		},{
	       			xtype : 'textfield',
					fieldLabel : '<a href="http://www.dms.com" target="_blank">公司网址</a>',
					value : 'http://www.dms.com'
	       		},{
	       			xtype : 'textfield',
					fieldLabel : '服务热线',
					value : '400-622-8990/0755-2698-0062'
				},{
					xtype : 'textfield',
					fieldLabel : '<a href="mailto:support@dms.com">邮箱地址</a>',
					value : 'support@dms.com'
				},{
					xtype : 'textfield',
					fieldLabel : '<a href="http://weibo.com/ankkitechnology" target="_blank">官方微博</a>',
					value : 'http://weibo.com/ankkitechnology'
				},{
					xtype : 'panel',
					layout : 'column',
					width : 700,
					items : [{
						layout: 'form',
						labelWidth:92,
						items : [{
							xtype: 'box', //或者xtype: 'component',
					    	fieldLabel : '官方微信',
						    autoEl: {  
						        tag: 'img',    //指定为img标签  
						        src: 'resources/images/loginQrcode.png'    //指定url路径  
						    } 						
						}]
					}]
				}]
			}]
		});
		win.show();
	}
	
	function LeaveWin() {
		location.href="logOutAction.action";
	}
	
	var logOutAction = function(){
		parent.Ext.MessageBox.confirm('提示', '确定退出系统？', function(btn) {
		if (btn == 'yes') {
			top.location.href="logOutAction.action";
		}});
	}
	
	
	var content = function(){
	
		var htmlContent = '<table id ="system" style="word-break: break-all" width="550" border="1px" cellspacing="0" cellpadding="0">' +
						'<tr style="color:red; text-align:center; font-size:15px;width :300px"><td >系统核心指标：</td>' +
						'<td >运行状况</td></tr>' +
						'<tr><td style="float:left;color:blue; text-align:left; font-size:15px;width :300px;line-height: 300%">CPU使用率：<p style="float:right" id="cpuData"></p></td>' +
						'<td id="status1" style ="font-size: 15px;text-align: center">正常</td></tr>' +
						'<tr><td style="color:blue; text-align:left; font-size:15px;width :300px;line-height: 300%">系统内存使用率:<p style="float:right" id="memoryData"></p></td>' +
						'<td id="status2" style ="font-size: 15px;text-align: center">正常</td></tr>' +
						'<tr><td style="color:blue; text-align:left; font-size:15px;width :300px;line-height: 300%">硬盘使用率:<p style="float:right" id="diskData"></p></td>' +
						'<td id="status3" style ="font-size: 15px;text-align: center">正常</td></tr>' +
						'<tr><td style="color:blue; text-align:left; font-size:15px;width :300px;line-height: 300%">审计口流量：<p style="float:right" id="auditData"></p></td>' +
						'<td id="status4" style ="font-size: 15px;text-align: center">正常</td></tr>' +
						'<tr><td style="color:blue; text-align:left; font-size:15px;width :300px;line-height: 300%">审计引擎状态：<p style="float:right" id="engineData"></p></td>' +
						'<td id="status5" style ="font-size: 15px;text-align: center">正常</td></tr>' +
						'</table>'
		
		return htmlContent;	
			
	};
	
	function risk() {
		service.riskInfor( {
			callback : function(data) {
				var arr = data.split(",");
				if(document.getElementById('highRisk_info_id') != null ||
				   document.getElementById('lowRisk_info_id') != null ||
				   document.getElementById('middleRisk_info_id') != null)
				{
					document.getElementById('highRisk_info_id').innerHTML = "<span class=\"alert-danger-icon\"></span>" + arr[0]; //high是action中返回的json字符串
					document.getElementById('middleRisk_info_id').innerHTML ="<span class=\"alert-warning-icon\"></span>" + arr[1]; //medium是action中返回的json字符串
					document.getElementById('lowRisk_info_id').innerHTML ="<span class=\"alert-tips-icon\"></span>" + arr[2]; //low是action中返回的json字符串
				}
				if(arr[3] != 'none'){
					window.parent.updateRiskReportInfo(arr[3]);
				}else if(arr[0] == 0 && arr[1] == 0 && arr[2] == 0){
					//TODO 后面程序可以自动去刷新日历风险统计
				}
			},
			errorHandler:function(errorString, exception){
				window.clearInterval(risk);
			}
		});
	}
	function lockYorN(){
		var passstatus = document.getElementById("passstatus").value;
		if(passstatus=="overdue"){
			changePassword();
		}
	    var passstatus = document.getElementById("unlock").value;
		if(passstatus=="YES"){
			lockConversasion();
		}
	}
	
</script>
<body onload="risk();lockYorN();dwr.engine.setActiveReverseAjax(true);dwr.engine.setNotifyServerOnPageUnload(true);onPageLoad();">
	<input type="hidden" id="tim" />
	<input type="hidden" id="loginTimeout" />
	<input type="hidden" id="verify" />
	<div style="display: none" id="bottom" title="用户信息" border="false"
		height="100%">
		<table cellpadding=0 cellspacing=0 width="100%" height="100%"
			bgcolor="#DEECFD">
			<tr>
				<td height="100%" width="25%" align='left'>
					<div id="tracePath"></div>
				</td>
			</tr>
		</table>
	</div>
	<input type="hidden" id="passstatus" value="<%= passstatus%>" />
	<input type="hidden" id="unlock" value="<%= unlock%>" />
</body>
<script type="text/javascript">
		LoginTimeout = 12;
		pageId = "<%=firstPageId%>";
		lastLoginTime = '<%=lastLoginTime%>';
		NowLoginTime = '<%=NowLoginTime%>';
		lastToNowHigh = <%=lastToNowHigh%>;
		lastToNowMiddle = <%=lastToNowMiddle%>;
		lastToNowLow = <%=lastToNowLow%>;
		companyNameJS = '<%=companyName%>';
		roleStrJs = '<%=roleStr%>';
		
		<%request.getParameter("returnMesg");%>
		var returnMesg = '${returnMesg}';
		if(returnMesg == 'the_passwdOfCount_willPass'){
			Ext.Msg.alert("提示", "您的密码马上过期，请及时修改。");
		}
		isSysAdmin = false;
		if(pageId == 'adminFirstPageId'){
			isSysAdmin = true;
		}
	</script>
</html>